package parsers;

import java.util.Iterator;

import object.Student;
import object.StudentList;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class StudentListParser {
	
	private StudentList students;
	
	public StudentListParser(){
		
	}
	
	public StudentListParser(StudentList students){
		this.students=students;
	}
	
	public void setStudentList(StudentList students){
		this.students=students;
	}
	
	public Element parse(Document doc){
		if(doc==null||students==null){
			System.err.println("doc or students cannot be null!");
			return null;
		}
		
		Element studentListE=doc.createElement("学生列表");
		Iterator<Student> itor=students.iterator();
		StudentParser sParser=new StudentParser();
		while(itor.hasNext()){
			Student student=itor.next();
			sParser.setStudent(student);
			Element studentE=sParser.parse(doc);
			studentListE.appendChild(studentE);
		}
		
		return studentListE;
	}

}
